#!/bin/bash

set -eo pipefail

if [[ ! -x "$(command -v go)" ]]; then
  echo >&2 "go runtime is required: https://golang.org/doc/install"
  echo >&2 "You can use scripts/go-wrapper $0 to use go in a docker container."
  exit 1
fi

golinter_path="${GOPATH}/bin/golangci-lint"

if [[ ! -x "${golinter_path}" ]]; then
    go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
fi

SOURCE_DIRECTORY=$(dirname "${BASH_SOURCE[0]}")
cd "${SOURCE_DIRECTORY}/.."

if [[ -n $1 ]]; then
    golangci-lint run "$1"
else
    golangci-lint run ./...
fi
